<template>
  <div>
    <el-form ref="formRef" :model="formData" :rules="rules" size="default" label-width="100px">
      <el-row gutter="15">
        <el-form-item label="老人姓名" prop="name">
          <el-input v-model="formData.name" type="text" placeholder="请输入老人姓名" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idcard">
          <el-input v-model="formData.idcard" type="text" placeholder="请输入身份证号" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-row>
      <el-row gutter="15">
        <el-form-item label="出生日期" prop="csrq">
          <el-date-picker v-model="formData.csrq" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
            :style="{width: '100%'}" placeholder="请选择出生日期" clearable></el-date-picker>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="formData.age" type="text" placeholder="请输入年龄" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-row>
      <el-row gutter="15">
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="formData.sex" size="default">
            <el-radio v-for="(item, index) in sexOptions" :key="index" :label="item.value"
              :disabled="item.disabled">{{item.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="联系方式" prop="iphone">
          <el-input v-model="formData.iphone" type="text" placeholder="请输入联系方式" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup>
import {
  ElMessage
}
from 'element-plus'
const formRef = ref()
const data = reactive({
  formData: {
    name: undefined,
    idcard: undefined,
    csrq: null,
    age: undefined,
    sex: 0,
    iphone: undefined,
  },
  rules: {
    name: [{
      required: true,
      message: '请输入老人姓名',
      trigger: 'blur'
    }],
    idcard: [{
      required: true,
      message: '请输入身份证号',
      trigger: 'blur'
    }],
    csrq: [{
      required: true,
      message: '请选择出生日期',
      trigger: 'change'
    }],
    age: [{
      required: true,
      message: '请输入年龄',
      trigger: 'blur'
    }],
    sex: [{
      required: true,
      message: '性别不能为空',
      trigger: 'change'
    }],
    iphone: [{
      required: true,
      message: '请输入联系方式',
      trigger: 'blur'
    }],
  }
})
const {
  formData,
  rules
} = toRefs(data)
const sexOptions = ref([{
  "label": "男",
  "value": 1
}, {
  "label": "女",
  "value": 2
}])
/**
 * @name: 表单提交
 * @description: 表单提交方法
 * @return {*}
 */
function submitForm() {
  formRef.value.validate((valid) => {
    if (!valid) return
    // TODO 提交表单
  })
}
/**
 * @name: 表单重置
 * @description: 表单重置方法
 * @return {*}
 */
function resetForm() {
  formRef.value.resetFields()
}

</script>
<style>
</style>
